package load.math;

import core.DispatcherPort;
import core.InPort;
import core.OutPort;
import core.StdNode;
import core.TriggerPort;
import java.util.Random;

/**
 *
 * @author Jennick
 */
public class RandomNumberGenerator extends StdNode {
    private Random rand = new Random();
    private DispatcherPort valueChanged = new DispatcherPort();
    
    private TriggerPort generate = new TriggerPort() {
        @Override
        public void callInternal() {
            valueChanged.callTargets();
        }
    };
    private OutPort res = new OutPort(Integer.class, valueChanged)
	{
		@Override
		public Object getValueInternal() {
			return Math.abs(rand.nextInt()) % (Integer) modulo.getValue()+1;
		}
	};
    private InPort modulo = new InPort(Integer.class, generate);

    public RandomNumberGenerator() {
        this.autoPutPorts();
    }
}